package com.lbs.jiepiaisi.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.regex.Pattern;

/**
 * Created by SiuWongLi on 16/10/30
 */
public final class ValidUtil {
    private static final String PHONE_FORMAT = "^((1[3,5,8][0-9])|(14[5,7])|(17[0,1,3,6,7,8]))\\d{8}$";
    private static final DateFormat DEFAULT_FORMAT = new SimpleDateFormat("yyyy.MM", Locale.getDefault());
    private ValidUtil(){
        new AssertionError();
    }
    //验证身份证号
    public static boolean validIdcard(String idcard){
        String validPattern =  "[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)";
        String validPattern1 =  "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)";
        return Pattern.matches(validPattern1,idcard);
    }
    //验证邮箱
    public static boolean validEmail(String email){
        String validPattern = "\\w+@\\w+\\.[a-z]+(\\.[a-z]+)?";
        return Pattern.matches(validPattern,email);
    }
    //验证手机号   ^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$
    public static boolean validPhone(String phone){
        String validPattern = "^((1[3,5,8][0-9])|(14[0-9])|(16[1,2,4,5,6,7])|(17[0-8])|(19[7]))\\d{8}$";
        return Pattern.matches(validPattern,phone);
    }
}
